<template>
  <view>
    <view class='scan-box' @click='scanConfirm'>
      <view>
        <l-icon icon='ehssaoma'></l-icon>
        <view class='scan-tit'>扫一扫</view>
      </view>

    </view>
    <u-modal v-model='scanIsShow' zoom title='用户信息' ref='scan' confirm-text='点击扫码' @confirm='scanConfirm' async-close>
      <view class='model-box'>
        {{ text }}
      </view>
    </u-modal>
  </view>

</template>

<script>
const { Base64 } = require('js-base64')

export default {
  name: 'ScanPop',
  data() {
    return {
      scanIsShow: false,
      text: ''
    }
  },
  created() {

  },
  methods: {

    minInit() {
      this.$store.commit('judgeUserInfo', {
        callback: () => {
          // 没有填写过详细信息
          if (!this.userInfo.accounts || this.userInfo.accounts.length === 0) {
            this.text = '首次授权登录，请扫入厂码完善个人信息，或联系所在单位管理员。'
            this.scanIsShow = true
          } else {
            this.text = '请扫入厂二维码'
            // this.$store.commit('judgeScanDateTime', {
            //   needFn: () => {
            //     this.scanIsShow = true
            //   },
            //   unwantedFn: () => {
            //     this.scanIsShow = false
            //   }
            // })
          }
        }
      })
    },
    // 点击是否弹窗
    clickShowFn(callback = () => {
    }) {
      this.$store.commit('judgeScanDateTime', {
        needFn: () => {
          this.scanIsShow = true
        },
        unwantedFn: () => {
          callback()
        }
      })
    },
    scanConfirm() {
      if (this.$refs.scan) {
        this.$refs.scan.clearLoading()
      }

      const params = Base64.decode('eyJzZXJ2aWNlT3JnTmFtZSI6IuWNjua2pu+8iOmbhuWbou+8ieaciemZkOWFrOWPuCIsImJlbG9uZ09yZ0lkIjoiNzk4MjkiLCJiZWxvbmdPcmdOYW1lIjoi5Y2O5ram55S15YqbU0JVIiwic2VydmljZU9yZ0lkIjoiMSJ9')

      uni.navigateTo({
        url: `/pages/fillin/fillin?params=${encodeURI(params)}`
      })

      return

      uni.scanCode({
        onlyFromCamera: true,
        success: (res) => {
          console.log(`条码类型：${res.scanType}`)
          console.log(`条码内容：${res.result}`)
          uni.navigateTo({
            url: '/pages/fillin/fillin'
          })
        }
      })
    }
  }
}
</script>

<style lang='scss' scoped>
.model-box {
  padding: px2rpx(50);
  text-align: center;
}

.scan-box {
  position: fixed;
  right: px2rpx(20);
  bottom: px2rpx(20);
  background: #fff;
  border: 1PX solid #ccc;
  border-radius: 50%;
  width: px2rpx(100);
  height: px2rpx(100);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;

  .scan-tit {
    font-size: 10PX;
    color: #999;
  }
}
</style>
